<?php

/* @var $this \yii\web\View */
/* @var $content string */

use yii\helpers\Html;
use front\assets\AppAsset;
use yii\helpers\Url;

?>

<body class="m-add-adrs m-gds-adrs">
    <div class="list">
        <?php if($list){?>
            <?php foreach($list as $k=>$v){ ?>
                <table data-aid="<?php echo $v['id'];?>">
                    <tr>
                        <td><img src="/static/img/ico11.png" /></td>
                        <td class="list-addr-info"><p><span>收货地址</span><em class="addr-new"><?php echo $v['address'];?></em></p>
                            <h5><b>收货人:<span class="addr-name"><?php echo $v['name'];?></span></b>
                                <span class="addr-tel"><?php echo $v['mobile'];?></span></h5>
                        </td>
                        <td><a href="/web/order/editaddrinfo?id=<?php echo $v['id'];?>" id="J_editnewAddr" add-id="<?php echo $v['id'];?>">编辑</a></td>
                    </tr>
                </table>
            <?php } ?>
        <?php } ?>
    </div>
	<a href="javascript:;" class="add" id="J_addnewAddr">添加新的地址</a>
<!--    --><?php //if(empty($list)){?>
        <dl>
            <dt>秀贝想使用您的微信位置信息，以节省您的宝贵时间，您是否同意？</dt>
            <dd id="J_actBtn" class="f-cb">
                <a href="javascript:;">拒绝</a>
                <a href="javascript:;" class="z-agree" id="agree_get_local">同意</a>
            </dd>
        </dl>
    <div class="m-mask" id="J_mask"></div>
<!--    --><?php //} ?>
    <div class="m-transX" id="J_addAddressInfo">

        <iframe class="m-iframe" src="/web/order/addaddrinfo" style="" frameborder="no" border="0" marginwidth="0" marginheight="0" scrolling="no" allowtransparency="yes"></iframe>

    </div>

    <div class="m-transX" id="J_editAddressInfo">

        <iframe class="m-iframe" src="/web/order/editaddrinfo" style="" frameborder="no" border="0" marginwidth="0" marginheight="0" scrolling="no" allowtransparency="yes"></iframe>

    </div>

    <script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script>




	$(function(){
        var transX = 'z-transX';
        $('#J_addnewAddr').on('tap', function(){
            $('#J_addAddressInfo').addClass(transX);
        });

        $('#J_editnewAddr').on('tap', function(){
            $('#J_editAddressInfo').addClass(transX);
        });

		var Jmask = $('#J_mask'), JactBtn = $('#J_actBtn');
		JactBtn.on('touchend', 'a', function(){

			var _this = $(this);
			// 同意
            if(_this.hasClass('z-agree')){
//                WeixinJSBridge.invoke('editAddress' ,<?//=$parameters?>// ,function(res){
//                    if(res.err_msg == 'edit_address:ok'){
//                        console.log("收件人："+res.userName+"  联系电话："+res.telNumber+"  收货地址："+res.proviceFirstStageName+res.addressCitySecondStageName+res.addressCountiesThirdStageName+res.addressDetailInfo+"  邮编："+res.addressPostalCode);
                var params = {};
//                        var name = res.userName;
//                        var mobile = res.telNumber;
//                        var dist_cn_char = res.proviceFirstStageName + res.addressCitySecondStageName + res.addressCountiesThirdStageName;
//                        var address = res.addressDetailInfo;
                var name = "test";
                var mobile = "13112345678";
                var dist_cn_char = "中国 上海市 上海";
                var address = "微信地址1888号";
                params.name = name;
                params.mobile = mobile;
                params.dist_cn_char = dist_cn_char;
                params.address = address;
                $.post("", params, function(data) {
                    data = JSON.parse(data);
                    if(data.code == 0) {
                        $('<table data-aid=" ' + data.result.id + ' ">' +
                            '<tr>' +
                            '<td><img src="/static/img/ico11.png" /></td>' +
                            '<td class="list-addr-info"><p><span>收货地址</span><em class="addr-new">' + dist_cn_char + '_' + address + '</em></p>' +
                            '<h5><b>收货人:<span class="addr-name">' + name + '</span></b>' +
                            '<span class="addr-tel">' + mobile + '</span></h5>' +
                            '</td>' +
                            '<td><a href="/web/order/editaddrinfo?id=' + data.result.id + '" id="J_editnewAddr" add-id="' + data.result.id + '">编辑</a></td>' +
                            '</tr>' +
                            '</table>').appendTo($(".list"));
                        $("#j-addresschar",window.parent.document).text(dist_cn_char);
                        $("#j-name",window.parent.document).text('收货人: '+name);
                        $("#j-mobile",window.parent.document).text(mobile);
                        $("#J-address",window.parent.document).attr('data-site',data.result.id);
                    }else {
                        alert(data.message);
                    }
                });

//                    }
//                    else{
//                        alert("获取地址失败，请重新点击");
//                    }
//                });
            }

			_this.closest('dl').hide();
			Jmask.hide();
		});

        $(".list-addr-info").on('touchend', 'td', function(evt){
            var addr = $(this).find('.addr-new').text();
            var addr_name = $(this).find('.addr-name').text();
            var addr_tel = $(this).find('.addr-tel').text();
            var add_id = $(this).attr('data-aid');
            $(this).tap(function(){
                $("#j-addresschar",window.parent.document).text(addr);
                $("#j-name",window.parent.document).text('收货人: '+addr_name);
                $("#j-mobile",window.parent.document).text(addr_tel);
                $("#J-address",window.parent.document).attr('data-site',add_id);
            });
            parent.document.getElementById('J_addAddress').className = 'm-transX';
            evt.preventDefault();
            return false;
        });
           // getReturnAdd();


	});


</script>
</body>